/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package general.util;

import beans.DataSessionManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.ServletRequest;
import jpa.entity.Obra;
import jpa.entity.User;

/**
 *
 * @author isaias
 */
public class MyPassDataUtil {
     private static MyPassDataUtil instance = new MyPassDataUtil();

    public static MyPassDataUtil getInstance() {
        return instance;
    }

    public static DataSessionManagedBean getDataSessionManagedBean() {
        DataSessionManagedBean dataSessionManagedBean = (DataSessionManagedBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("dataSessionManagedBean");
        return dataSessionManagedBean;
    }

     public String getUserIp(){
        ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        return request.getRemoteAddr();
    }

    public User getCurrentUser() {
        DataSessionManagedBean dataSessionManagedBean = (DataSessionManagedBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("dataSessionManagedBean");
        return dataSessionManagedBean.getCurrentUser();
    }

    public Obra getCurrentObra() {
        DataSessionManagedBean dataSessionManagedBean = (DataSessionManagedBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("dataSessionManagedBean");
        return dataSessionManagedBean.getCurrentObra();
    }
}
